<div class="search-bar">
    <ul>
        <li>单据状态：</li>
        <li>
            <select id="status" class="province floatleft select1">
                <option value="-1" selected="selected">全部</option>
                <option value="0">处理中</option>
                <option value="1">成功</option>
                <option value="2">失败</option>
            </select>
        </li>
        <li>账变类型：</li>
        <li>
            <select id="log-type" class="province floatleft select1">
                <option value="-1" selected="selected">全部</option>
                <option value="deposit">充值</option>
                <option value="withdraw">出款</option>
                <option value="consume">下注</option>
                <option value="profit">盈利</option>
                <option value="reward">奖励</option>
                <option value="penalty">惩罚扣款</option>
                <option value="deduct">其他扣款</option>
                <option value="cancel">撤单</option>
                <option value="back">返水</option>
            </select>
        </li>
        
        <li class="marginleft10">起止日期：</li>
        <li>
            <input id="startDate"> ~ 
            <input id="endDate">
        </li>
        
        <li>
            <button type="button" class="btn">搜索</button>
        </li>
        <div class="clear"></div>
    </ul>
</div>

<div class="records">
    <table class="table">
        <thead>
            <tr class="trcolor">
                <th style="width: 10%">时间</th>
                <th style="width: 8%">类型</th>
                <th style="width: 6%">金额</th>
                <th style="width: 6%">余额</th>
                <th>交易描述</th>
                <th style="width: 8%">单据状态</th>
            </tr>
        </thead>
        <tbody id="paylist-tbody"><tr class="trcolor"><td colspan="6">暂无数据</td></tr></tbody>
    </table>
</div>

<div class="page_info">
    <div id="listPage" class="megas512 zxf_pagediv"></div>    
</div>
<div style="height:50px;"></div>

<script>
    (function() {
        $("#startDate").datepicker({format: 'yyyy-mm-dd'});
        $("#endDate").datepicker({format: 'yyyy-mm-dd'});

        $("#status").change(function() {
            Page.currPage = 1;
            queryChargeLogList(1);
        })

        var Page = new PageList();
        Page.pageSize = 15;
        Page.denyTrai = true;
        Page.jumpPage = function(page) {
            queryChargeLogList(page);
        }
        $(".search-bar .btn").click(function() {
            queryChargeLogList(1);
        });

        function queryChargeLogList(page) {
            var data = {
                owner: "",
                pageSize: Page.getPageSize(),
                pageNum: page || 1,
            };
            Page.currPage = page || 1;
            if ($("#status").val() != '-1') data.state = $("#status").val();
            if ($("#startDate").val() != '') data.start = $("#startDate").val().trim();
            if ($("#endDate").val() != '') data.end = $("#endDate").val().trim();
            if ($("#log-type").val() != '-1') data.type = $("#log-type").val();
            startLoading();
            CMD.query_account_log2(data, function(r) {
                stopLoading();
                Page.fillPages(r.count, r.number, r.page, r.size);
                fillChargeLogList(r.list);
            });
        }
        queryChargeLogList(1);

        function fillChargeLogList(list) {
            var table = $("#paylist-tbody"); table.empty();
            var count = 0;
            for (var i in list) {
                var d = list[i];
                if (count % 2 == 0)
                    var tr = $("<tr class='trcolor'></tr>");
                else
                    var tr = $("<tr></tr>");
                count++;

                tr.append('<td>' + d.start + '</td>');
                if (d.channel2)
                    tr.append('<td>' + Util.convertLogType(d.type) + "<br>" + Util.convertChannel(d.channel2) + '</td>');
                else
                tr.append('<td>' + Util.convertLogType(d.type) + '</td>');
                tr.append('<td>' + d.amount/100 + '</td>');
                tr.append('<td>' + d.balance/100 + '</td>');

                // 交易描述
                tr.append('<td>' + _convertDetail(d) + '</td>');
                if (d.state == 0) tr.append('<td>处理中</td>');
                else if (d.state == 1) tr.append('<td>成功</td>');
                else if (d.state == 2) tr.append('<td>失败</td>');

                table.append(tr);
            }
            if (Util.isEmpty(list)) {
                table.append("<tr><td colspan='7'>暂无数据</td></tr>");
                return;
            }
        }

        // 生成交易描述信息
        function _convertDetail(data) {
            var memo = {};
            if (data.memo) {
                try {
                    memo = JSON.parse(data.memo);
                }
                catch (e) {}
            }
            switch (data.type) {
                case "profit": {
                    return data.memo || '';
                    break;
                }
                case "consume":
                case "back": {
                    return data.memo || '';
                    break;
                }
                case "deposit": {
                    if (data.channel2 == 'bank') {
                        return "转入银行：" + memo.name + " &nbsp;&nbsp; " + memo.account + "(" + memo.bank + ")";
                    }
                    if (data.channel2 == 'alipay') {
                        return "转入支付宝：" + memo.name + "(" + memo.account + ")";
                    }
                    if (data.channel2 == 'wechat') {
                        return "转入微信：" + memo.account;
                    }
                    break;
                }
                case "withdraw": {
                    return "提款银行：" + memo.account + "(" + memo.bank + ")";
                    break;
                }
                case "fee": {
                    break;
                }
                case "cancel": {
                    return data.memo || '';
                    break;
                }
                case "reward": {
                    return "奖励原因：" + (memo.info || '无');
                    break;
                }
                case "deduct":
                case "penalty": {
                    return "扣款原因：" + (memo.info || '无');
                    break;
                }
            }
            return "";
        }
    })();
</script>